<?php
class HotelController extends Zend_Controller_Action
{
	private $_db = null;
	
	public function init(){
		$registry = Zend_Registry::getInstance();
		$this->_db = $registry->get('db');
	}
	
	public function indexAction()
	{
		Zend_Loader::loadFile("../application/default/models/Aboutcountry.php");
	}
	
	public function viewAction()
	{
                $breadcrumb= Array ("0" =>Array("title" => "Home", "url" => "/index/" ), "1"=>Array("title"=>$this->view->translate('%Reservations','topnav'), "url"=>"") );
		$this->view->breadcrumb()->set($breadcrumb);		
		$this->_helper->layout->setLayout('layout');
		Zend_Loader::loadFile("../application/default/models/Tour.php");
		Zend_Loader::loadFile("../application/default/models/Hotel.php");
		Zend_Loader::loadFile("../application/default/models/Aboutcountry.php");
		$controller = $this->getRequest()->getControllerName();
		$config = Zend_Registry::get('config'); 
                $itemperpage = $config->application->itemperpage;
                $this->view->controller = $controller;
		$hotel_model = new Hotel();		
		$hotel_arr = $hotel_model->getHotelDetails();

                $page=$this->_getParam('page',1);
                $paginator = Zend_Paginator::factory($hotel_arr);
                $paginator->setItemCountPerPage($itemperpage);
                $paginator->setCurrentPageNumber($page);

                $this->view->paginator=$paginator;
		$this->view->hotel_arr = $hotel_arr;				
	}
        public function ratesAction()
	{
		 
		 $arr=array();
		$this->_helper->layout()->disableLayout();
		Zend_Loader::loadFile("../application/default/models/Hotel.php");
		$controller = $this->getRequest()->getControllerName();
                $request = $this->getRequest();
		$hotel_id = $request->getParam('hotelid');
		$hotel_model = new Hotel();
		$rates_arr = $hotel_model->getHotelRates($hotel_id);
              //  $strucutedataarr=$hotel_model->getHotelRatesstructuredata($hotel_id);
                // print_r($strucutedataarr);
                foreach($rates_arr as $val){
                    $rateviewarr[$val["rate_id"]]['fromdate']=$val['fromdate'];
                    $rateviewarr[$val["rate_id"]]['todate']=$val['todate'];
                    
                    $strucutedataarr=$hotel_model->getHotelRatesstructuredata($val["rate_id"]);
                   //  print_r($strucutedataarr);exit;
                    foreach($strucutedataarr as $valuearr)
                    {
                        $rateviewarr[$val["rate_id"]]['tdarr']["rate_category"][$valuearr["id"]]=$val['rate_category'];
                         $rateviewarr[$val["rate_id"]]['tdarr']["rate_additionalinfo"][$valuearr["id"]]=$val['rate_additionalinfo'];
                        $rateviewarr[$val["rate_id"]]['tdarr']["rate_basis"][$valuearr["id"]]=$val['rate_basis'];
                        $rateviewarr[$val["rate_id"]]['tdarr']['ratekey'][$valuearr["id"]]=$valuearr['ratekey'];
                        $rateviewarr[$val["rate_id"]]['tdarr']['rateval'][$valuearr["id"]]['FB']=$valuearr['ratevalFB'];
                        $rateviewarr[$val["rate_id"]]['tdarr']['rateval'][$valuearr["id"]]['HB']=$valuearr['ratevalHB'];
                        $rateviewarr[$val["rate_id"]]['tdarr']["ratetype"][$valuearr["id"]]=$valuearr['ratetype'];
                    }
                }
             //  print_r($rateviewarr);  exit;
              /*  $this->view->strarr = $arr;
		$this->view->rates_arr = $rates_arr;*/
                $this->view->rateviewarr = $rateviewarr;
	}
	
	public function detailsAction()
	{
		$request = $this->getRequest();
		$req = $request->getParam('req');
		
		if($req == "quicksearch")
		{
			$this->_helper->layout()->disableLayout();
		} else {
			$this->_helper->layout->setLayout('layout');
		}
		
		
		$breadcrumb= Array ("0" =>Array("title" => "View Hotels", "url" => "/hotel/view/" ) ,"1" => Array("title" =>"Hotel Details","url"=>"" ) );
		$this->view->breadcrumb()->set($breadcrumb);
		
		//$this->_helper->layout()->disableLayout();
		Zend_Loader::loadFile("../application/default/models/Tour.php");
		Zend_Loader::loadFile("../application/default/models/Hotel.php");
		Zend_Loader::loadFile("../application/default/models/Aboutcountry.php");
		
                $sess = new Zend_Session_Namespace('locale');
                $curr_lang = $sess->current_lang;
                if($curr_lang != '')
                {
                    $lang = $curr_lang;
                } else {
                    $lang = 'en';
                    }
		$controller = $this->getRequest()->getControllerName();
		$this->view->controller = $controller;
	    
		$hotel_model = new Hotel();
		
		$hotel_id = $request->getParam('hotelid');
		$hotel_arr = $hotel_model->getHotelDetailsById($hotel_id);
		$hotel_img_arr = $hotel_model->getHotelImageByHotelId($hotel_id);
		$amenity_arr = $hotel_model->getAmenitiesByHotelId($hotel_id);		
		
		$this->view->amenity_arr = $amenity_arr;
		$this->view->hotel_id = $hotel_id;
		$this->view->hotel_arr = $hotel_arr;
		$this->view->hotel_img_arr = $hotel_img_arr;
		$this->view->lang = $lang;
	}
	
	public function bookingAction()
	{
            $request = $this->getRequest();
		$req = $request->getParam('req');
		
		if($req == "quicksearch")
		{
			$this->_helper->layout()->disableLayout();
		} else {
			$this->_helper->layout->setLayout('layout');
		}                
                $breadcrumb= Array ("0" =>Array("title" => "hotel", "url" => "/hotel/view/" ) ,"1" => Array("title" =>"booking","url"=>"" ) );
                $this->view->breadcrumb()->set($breadcrumb);		
		Zend_Loader::loadFile("../application/default/models/Hotel.php");
		Zend_Loader::loadFile("../application/default/models/Tour.php");
		Zend_Loader::loadFile("../application/admin/models/Roomcats.php");
		Zend_Loader::loadFile("../application/default/models/Common.php");
		Zend_Loader::loadFile("../application/default/models/Aboutcountry.php");
		$sess = new Zend_Session_Namespace('locale');
        $curr_lang = $sess->current_lang;
        if($curr_lang != '')
        {
            $lang = $curr_lang;
        } else {
    	    $lang = 'en';
	    }
		$hotel_model = new Hotel();
		$roomcat_model = new Roomcats();
		$common_model = new Common();
		$request = $this->getRequest();
		$hotel_id = $request->getParam('hotelid');
		$this->view->hotel_id = $hotel_id;
		$hotel_arr = $hotel_model->getHotelDetailsById($hotel_id);                
                $this->view->hotel_arr = $hotel_arr;
		$room_cat_arr = $roomcat_model->listroomcats();
		$this->view->room_cat_arr = $room_cat_arr;
		$country_arr = $common_model->getDefaultCountryList();
		$this->view->country_arr = $country_arr;
		$this->view->lang = $lang;		
	}
	
	public function getroomtypeAction()
	{
		$room_cat_id = $_POST['roomcat_id'];
		
		$html="<option value=''>Room Types</option>";
		Zend_Loader::loadFile('../application/default/models/Hotel.php');
		$mod_hotel = new Hotel();
		
		$room_types_arr = $mod_hotel->getRoomTypeByCatId($room_cat_id);
		
		foreach ($room_types_arr as $room_types){
			$room_types = explode("|", $room_types['room_type']);
			for ($i=0; $i<count($room_types); $i++) {
				if(!empty($room_types[$i])) {
					$html .= '<option value="' . $room_types[$i] . '">' . ucfirst($room_types[$i]) . '</option>';
				}
			}
			//$html .= '<option value="' . $room_types['city_id'] . '">' . $room_types['city_name'] . '</option>';
		}
	
		echo $html ;
		exit;
	}
	
	public function sendbookingrequestAction() 
	{            
		$this->_helper->layout->setLayout('layout');
		Zend_Loader::loadFile('../application/default/models/Hotel.php');
		Zend_Loader::loadFile("../application/default/models/Aboutcountry.php");
		Zend_Loader::loadFile('../library/Zend/Mail.php');
		$config = new Zend_Config_Ini('../application/config/db_config.ini', 'common');
		$admin_email = $config->application->adminemail;
		$mod_hotel = new Hotel();
		$mail = new Zend_Mail();
		$request = $this->getRequest();
		if ($request->isPost()) {            			
			$form_values = $request->getPost();
			//$send_request = $mod_hotel->sendBookingRequest($form_values);
			
			$subject = "Booking Request";
			
			$msg = "<p>Hello Admin, <p>";
			$msg .= "<p>I would like to make a booking request</p>";
			
                        
			$msg .= "<p style='text-transform:capitalize;'>" . (!empty($form_values['module'])?$form_values['module']:"") . (!empty($form_values['module_val'])?" - " . $form_values['module_val']:"") ."</p>";
	
                        $msg .= "<p>Booking Info<br />----------------------------------------------------------------------</p>";
			
			$msg .= "<p>From: " . $form_values['checkin'] . "  To: " . $form_values['checkout'] . "</p>";
			$msg .= "<p>No.of nights: " . $form_values['no_nights'] . "</p>";
			$msg .= "<p>No.of rooms: " . $form_values['rooms'] . "</p>";
			$msg .= "<p>Room category: " . $form_values['roomcat'] . "</p>";
			$msg .= "<p>Room type: " . $form_values['roomtype'] . "</p>";
			$msg .= "<p>Adults: " . $form_values['adult'] . "</p>";
                        $msg .= "<p>No. of infants(0-3 years): " . $form_values['infants'] . "</p>";
			$msg .= "<p>No. of children (3-12 years): " . $form_values['children'] . "</p>";
		
			if($form_values['additional_info'] != "") {
				$msg .= "<p>Additional room is needed </p>";
			}
			
			if($form_values['transfer_option'] != "") {
				$msg .= "<p>Airport Transfer is needed </p>";
                                $msg .= "<p>Airport Transfer Type</p>:".$form_values['transfertype'];
			}
			
			$msg .= "<p>Personal Info<br />----------------------------------------------------------------------</p>";	
			
			$msg .= "<p>Name: " . $form_values['fullname'] . "</p>";
			$msg .= "<p>Email Address: " . $form_values['email'] . "</p>";
			
			if($form_values['telephone'] != "") {
				$msg .= "<p>Contact No: " . $form_values['telephone'] . "</p>";
			}
			
			$msg .= "<p>Postal Address: " . $form_values['address'] . "</p>";
			$msg .= "<p>Country: " . $form_values['country'] . "</p>";
			$msg .= "<p>Comment: " . $form_values['comments'] . "</p>";
			
			$msg .= "<p>Thank You </p></p>";
			$msg .= "<p>" . $form_values['fullname'] . "<br />----------------------------------------------------------------------</p>";
			$msg .= "<p>You got this message from " . $_SERVER['REMOTE_ADDR'];
			//exit($msg);
		    $mail->setBodyHtml($msg);
		    $mail ->setFrom($form_values['email'], $form_values['fullname']);
		    $mail->setSubject($subject);
			
		    // for the testing purpose we are sending email to the localhost.
		    //$mail->addTo("info@localhost"); 
                    $mail->addTo($admin_email); 
		    if($mail->send()) {
		    	echo "Your booking request has been successfully sent. One of our staff member will be contact you soon.";
		    }
		    exit;
		}
	}
	
	public function sendquickbookingrequestAction() {
		Zend_Loader::loadFile("../application/default/models/Tour.php");
		Zend_Loader::loadFile("../application/default/models/Aboutcountry.php");
		$config = new Zend_Config_Ini('../application/config/db_config.ini', 'common');
		$admin_email = $config->application->adminemail;
		
		$mail = new Zend_Mail();
		$request = $this->getRequest();
		if ($request->isPost()) {            			
			$form_values = $request->getPost();
			//print_r($form_values);
			$subject = "Quick Booking Request";
			
			$msg = '<style type="text/css" media="screen">';
			$msg .= '* { margin: 0; padding: 0; }
					html, body{ margin: 0; padding: 0; }
					body,td{font-family:arial;font-size :12px;}
					.style1 {font-size: 14px}
					body {
						font-family : verdana, helvetica, sans-serif;
						font-size : 10pt;
						background-color: transparent;
					}
					h1{
						float:left;
						width:85%;
						background-color:#CCCCCC;
						color:#333333;
						text-align:left;
						padding:5px 0 5px 5px;
						margin:15px 0 10px 5px;
						border:1px solid #888;
						font-size:18px;
					}
					p{
						line-height:1.5;
					}
					table{
						float:left;
						width:85%;
						margin:0 0 0 5px;
					}
					td{
					    font-size : 10pt;
						text-align: left;
						border-bottom:1px solid #DEDEDE;
						padding:7px 5px 7px 5px;
					}
					td.FieldName{
						font-weight:bold;
						vertical-align: top;
					}
					td.FieldValue {
						font-family : Verdana, Helvetica, sans-serif;
						font-size : 10pt;
					}
					td.ExtraInfoName {
						font-family :;
						font-size : 8pt;
						border-bottom:0px;
						font-weight:bold;
					}
					td.ExtraInfoValue {
						font-family : Verdana, Helvetica, sans-serif;
						font-size : 8pt;
						border-bottom:0px;
					}
					fieldset {
						display:block; 
						border:#000000 solid;
					        border-width: 1px 0 0 0;
						padding:10px; 
						font-family:Arial, Helvetica, sans-serif;
						margin-bottom:0.5em; 
					}legend{
						font-size:14px;
						font-family:Arial, Helvetica, sans-serif;
						font-weight:bold;
					}';
			$msg .= "</style>";
			
			$msg .= '<p style="margin:15px 0 0 5px;">Hello Admin,<br/>I would like to make a booking request.</p>';
			$msg .= '<h1>Booking info :</h1>';
			$msg .= '<table cellspacing="0" cellpadding="6">';
  			$msg .= '<tbody>';
			$msg .= '<tr>';
			$msg .= '<td width="190" class="FieldName" valign="top" align="left"><div align=right>From (Check-in) :</div></td>';
			$msg .= '<td width="170" align="left" valign="top" class="FieldValue"><p align="left">' . $form_values['date18'] . '</p></td>';
			$msg .= '<td width="126" align="left" valign="top" class="FieldName"><div align="right">To (Check-out) :</div></td>';
			$msg .= '<td width="1312" align="left" valign="top" class="FieldValue"><p align="left">' . $form_values['date10'] . '</p></td>';
			$msg .= '</tr>';
			$msg .= '<tr>';
			$msg .= '<td align="left" valign="top" class="FieldName"><div align=right>Adults :</div></td>';
			$msg .= '<td align="left" valign="top" class="FieldValue"><p align="left">' . $form_values['adults'] . '</p></td>';
			$msg .= '<td align="left" valign="top" class="FieldName"><div align="right">Children :</div></td>';
			$msg .= '<td align="left" valign="top" class="FieldValue"><p align="left">' . $form_values['children'] . '</p></td>';
			$msg .= '</tr>';
			$msg .= '</tbody>';
			$msg .= '</table>';
			$msg .= '<h1>Personal info :</h1>';
			$msg .= '<table cellspacing="0" cellpadding="5" >';
			$msg .= '<tbody>';
			$msg .= '<tr>';
			$msg .= '<td width="184" class="FieldName" valign="top" align="left"><p align=right>Name  :</p></td>';
			$msg .= '<td width="1700" colspan="2" align="left" valign="top" class="FieldValue"><p align="left">' . $form_values['sender_name'] . '</p></td>';
			$msg .= '</tr>';
			$msg .= '<tr>';
			$msg .= '<td class="FieldName" valign="top" align="left"><p align=right>E-mail :</p></td>';
			$msg .= '<td class="FieldValue" valign="top" align="left" colspan="2"><p align="left">' . $form_values['sender_email'] . '</p></td>';
			$msg .= '</tr>';
			$msg .= '<tr>';
			$msg .= '<td class="FieldName" valign="top" align="left"><p align=right>Country :</p></td>';
			$msg .= '<td class="FieldValue" valign="top" align="left" colspan="2"><p align="left">' . $form_values['cmbCountry'] . '</p></td>';
			$msg .= '</tr>';
			$msg .= '<tr>';
			$msg .= '<td class="FieldName" valign="top" align="left"><p align=right>City :</p></td>';
			$msg .= '<td class="FieldValue" valign="top" align="left" colspan="2"><p align="left">' . $form_values['cmbCity'] . '</p>';
			$msg .= '<p align="left">Fghdfgh dtghdftgh</p></td>';
			$msg .= '</tr>';
			$msg .= '<tr>';
			$msg .= '<td class="FieldName" valign="top" align="left"><p align=right>Hotel :</p></td>';
			$msg .= '<td class="FieldValue" valign="top" align="left" colspan="2"><p align="left">' . $form_values['cmbHotel'] . '</p>';
			$msg .= '</tr>';
			$msg .= '</tbody>';
			$msg .= '</table>';
			
			$msg .= '<h1>Other info :</h1>';
			$msg .= '<table cellspacing="0" cellpadding="5" >';
			$msg .= '<tbody>';
			$msg .= '<tr>';
			$msg .= '<td class="ExtraInfoName" valign="top" align="left" width="170"><div align="right">Booking Submission Date &amp; Time : </div></td>';
			$msg .= '<td class="ExtraInfoValue" valign="top" align="left" ><div align="left"> ' . date('Y-m-d h:i:A') . ' </div></td>';
			$msg .= '</tr>';
			$msg .= '<tr>';
			$msg .= '<td class=ExtraInfoName valign="top" align="left"><div align="right">Sender\'s IP : </div></td>';
			$msg .= '<td class="ExtraInfoValue" valign="top" align="left"><div align="left">' . $_SERVER['REMOTE_ADDR'] . '</div></td>';
			$msg .= '</tr>';
			$msg .= '</tbody>';
			$msg .= '</table>';
			
			$mail->setBodyHtml($msg);
		    $mail ->setFrom($form_values['sender_email'], $form_values['sender_name']);
		    $mail->setSubject($subject);
			
		    // for the testing purpose we are sending email to the localhost.
		    $mail->addTo($admin_email); 
		    //$mail->send();
		    if($mail->send()) {
		    	echo "<script language='javascript'>location.href='/index/index/msg/" . md5('mailsent') . "';</script>";
		    }
		}
	}
}	
?>	